/*
 * =====================================================================================
 *
 *       Filename:  UserTime.h
 *
 *    Description:  高精度计时器
 *
 *        Version:  1.0
 *        Created:  2011-11-15 10:22:29
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  YOUR NAME (),
 *        Company:
 *
 * =====================================================================================
 */

#ifndef _USER_TIME_H_
#define _USER_TIME_H_

#include <windows.h>

class CUserTime
{
    LARGE_INTEGER m_nFreq;
    LARGE_INTEGER m_nBeginTime;
    LARGE_INTEGER nEndTime;
public:
    CUserTime(void) {
        start();
    }
    void start(void) {
        QueryPerformanceFrequency(&m_nFreq); // 获取时钟周期
        QueryPerformanceCounter(&m_nBeginTime); // 获取时钟计数
    }
    double lapse(void) {
        QueryPerformanceCounter(&nEndTime);
        return 1000 * (double)(nEndTime.QuadPart - m_nBeginTime.QuadPart) / (double)m_nFreq.QuadPart;
    }
};

#endif
